package logic

import (
	"activity_srv/activity"
	"activity_srv/internal/dao"
	"activity_srv/internal/svc"
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateSeckillGoodLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateSeckillGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSeckillGoodLogic {
	return &CreateSeckillGoodLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateSeckillGoodLogic) CreateSeckillGood(in *activity.CreateSeckillGoodRequest) (*activity.CreateSeckillGoodResponse, error) {
	seckillGood, err := dao.CreateSeckillGood(in) // 创建秒杀商品
	if err != nil {
		pkg.Error("创建秒杀商品失败", zap.Error(err)) // 记录日志
		return nil, err
	}
	return &activity.CreateSeckillGoodResponse{
		SeckillGoodId: int64(seckillGood.Id), // 返回秒杀商品ID
	}, nil
}
